<template>
    <div class="exam-wrap">
        <div class="coming-wrap">
            <!-- <mt-cell v-for="(item,index) in examlist" :key="index" :label="item.time" :title="item.title" @click.native.capture="linkFun(item.id)" is-link class="text-left list-cell">hgjgsdfj</mt-cell> -->
            
            <div class="mint-cell-wrapper" v-for="(item,index) in examlist" :key="index" @click="linkFun(item.id)">
                <div class="mint-cell-title">
                    <span class="mint-cell-text">{{item.title}}<i class="scope-sign">{{item.scope == 1?'全院' : '本科'}}</i></span> 
                    <span class="mint-cell-label">{{item.time}}</span>
                </div> 
                <div class="mint-cell-value is-link">
                    <mt-button v-if="item.scope == 2 && userRole == 9" type="primary" size="small" @click="prevtest(item.id)">添加考生</mt-button>
                </div> 
                <i class="mint-cell-allow-right"></i>
            </div>

        </div>
    </div>
</template>
<style>
    .mint-cell-wrapper{
        position: relative;
        background: none;
        padding: 10px;
        border-bottom: 1px solid #d9d9d9;
    }
    .scope-sign{
        background: #ef4f4f;
        font-style: inherit;
        color: #fff;
        padding: 1px 3px;
        border-radius: 5px;
        font-size: 12px;
        margin-left: 3px;
    }
    .mint-button--small{
        height: 22px;
        font-size: 12px;
        padding: 0px 5px;
    }
    .mint-button-text{
        font-size: 12px;
    }
</style>
<script>
    import conf from '../config/userconf.js'
    export default {
        name: 'coming',
        data(){
            return{
                examlist: [],
                userRole: '',  //当前身份
            }
        },
        methods: {
            init(data=null){

                this.userRole = window.localStorage.userRole;

                conf.exams.cominglist(data,(state,res)=>{
                    if (state == 'success'&&res.data.status == 1){
                        // console.log(res.data);
                        this.examlist =  res.data.other.list;
                        for(var i=0;i<this.examlist.length;i++){
                            this.examlist[i].time = this.examlist[i].showStartTime + '  --  ' + this.examlist[i].showEndTime;
                        }
                        
                    }else if(state == 'success'&&res.data.status != 1){
                        this.$toast(res.data.message);
                    }
                })
            },
            linkFun(id,data=Object()){
                // console.log(id);
                    
                //用户身份   8 科主任   9科秘书   10 考生 
                if(window.localStorage.userRole == 10){

                    data.id = id;
                    conf.exams.iscanStart(data,(state,res)=>{
                        if (state == 'success'&&res.data.status == 1){
                            // console.log(res.data);
                            this.$router.push({path: '/exam', query: {id: id}})
                            
                        }else if(state == 'success'&&res.data.status != 1){
                            this.$toast(res.data.message);
                        }
                    })
                    

                }
            },
            //添加考生   科秘书
            prevtest(id){
                this.$router.push({path: '/addexaminee', query: {id: id}})
            },
        },
        mounted() {
            this.init();
            document.title = "即将开始考试";
        }
    }
</script>
